<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<style type="text/css">
.dateWidth1{
   width:195px;
}
.selectWidth2{
   width:205px;
}
.file {
    display: none;
}
.dataSize{
	width:50px;
}
</style>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<div class="t_bar">执行情况</div>
<table id="tblJshtZxqk" cellpadding="0" class="table01 t_css"
	width="100%" border="0" cellpadding="0"
	style="border-bottom: #a1c0dc 1px solid;">
	<col style="width: 5%">
	<col style="width: 5%">
	<col style="width: 10%">
	<col style="width: 10%">
	<col style="width: 10%">
	<col style="width: 10%">
	<col style="width: 10%">
	<col style="width: 10%">
	<col style="width: 15%">
	<col style="width: 15%">

	<thead>
		<tr style="border: 1px solid #B7D1E6">
			<th class="TblHead" align="center">选择</th>
			<th class="TblHead" align="center">序号</th>
			<th class="TblHead" align="center">是否已到国税备案</th>
			<th class="TblHead" align="center">发票代码</th>
			
			<th class="TblHead" align="center">发票号码</th>
			<th class="TblHead" align="center">发票金额<br/>(万元)</th>
			<th class="TblHead" align="center">备案税务机关</th>
			<th class="TblHead" align="center">备案时间</th>
			<th class="TblHead" align="center">发票扫描件</th>
			<th class="TblHead" align="center">国税局备案表的扫描件</th>
		</tr>
	</thead>
	<tbody id="tab">
		<tr style="display: none">
			<td align="center"><input type="radio" class="radiobutton"
				name="selJshtZxqk"></td>
			<td align="center"><span name="jshtzxqks|jshtzxqk[0]@seq_no">[index]</span>
			</td>
			<td align="center">
				<input id="isba[0]_value" name="jshtzxqks|jshtzxqk[0]|isba_value" type="hidden" class="required" label="是否已到国税备案" value="" />
				<input id="isba[0]_name" name="jshtzxqks|jshtzxqk[0]|isba_name" type="hidden" value="" />
				<select id="isba[0]" onchange="initselectvalue(this.id)">
					<option value=""></option>
					<option value="1">是</option>
					<option value="0">否</option>
				</select>
			
			</td>
			<td align="center"><input style="width:80%" type="text" value="" label="发票代码" name="jshtzxqks|jshtzxqk[0]|fpdm" class="input_css required">
			</td>
			<td align="center"><input style="width:80%" type="text" value="" label="发票号码" name="jshtzxqks|jshtzxqk[0]|fphm" class="input_css required">
			</td>
			<td align="center"><input style="width:80%" type="text" value="" label="发票金额" onfocus="InitInput.setNumber(this,7,4,2)" name="jshtzxqks|jshtzxqk[0]|fpje" class="input_css required">
			</td>
			<td align="center"><div><input style="width:80%" type="text" value="" label="备案税务机关" name="jshtzxqks|jshtzxqk[0]|baswjg" class="input_css required">
			</div></td>
			<td align="center">
			<div>
			<cpt:date name="jshtzxqks|jshtzxqk[0]|basj" label="备案时间" id="basj[index]" value="" className="dataSize date"></cpt:date>
			</div>
			</td>
			<td align="center">
				<input type="hidden" id="jshtzxqk[0]_file_code" class="required" name="jshtzxqks|jshtzxqk[0]|file_code" value=""  label="发票扫描件" />
				<input type="hidden" id="jshtzxqk[0]_entity_file_name"  name="jshtzxqks|jshtzxqk[0]|entity_file_name" value=""  />
				<span><a id="jshtzxqk[0]_a" class="color_blue"  href="${ctx}/file/ajax-filedownload?fileCode=" ></a><br></span>
				<div><input type="file" name="filedata" id="jshtzxqk[0]" /><button id="button_[0]" onclick="deleteFile('jshtzxqk[0]')" class="button_02">删除</button>
				</div>
			</td>
			<td><div>
				<input type="hidden" id="jshtzxqk[0]r_file_code"  name="jshtzxqks|jshtzxqk[0]|file_code2" value=""  label="国税局备案表的扫描件" />
				<input type="hidden" id="jshtzxqk[0]r_entity_file_name"  name="jshtzxqks|jshtzxqk[0]|entity_file_name2" value=""  />
				<input type="hidden" id="jshtzxqk[0]r_entity_file_name"  name="jshtzxqks|jshtzxqk[0]|index2" value=""  />
				<span ><a id="jshtzxqk[0]r_a" class="color_blue"  href="${ctx}/file/ajax-filedownload?fileCode=" ></a><br></span>
				<div><input type="file" name="filedata" id="jshtzxqk[0]r" /><button id="button2_[0]" onclick="deleteFile('jshtzxqk[0]r')" class="button_02">删除</button>
				</div>
				</div>
			</td>

		</tr>


		<c:set value="0" var="index" scope="page" />
		<x:forEach select="$xmlData/data/jshtzxqks/jshtzxqk" var="jshtzxqk">

			<c:choose>
				<c:when test="${index<10}">
					<c:set value="0" var="flag" scope="page" />
				</c:when>
				<c:otherwise>
					<c:set value="" var="flag" scope="page" />
				</c:otherwise>
			</c:choose>
			<tr>
				<td align="center"><input type="radio" class="radiobutton"
					name="selJshtZxqk"></td>
				<td align="center"><span
					name="jshtzxqks/jshtzxqk[${flag}${index}]@seq_no"><x:out
							select="$jshtzxqk/@seq_no" /></span></td>
				<td align="center">
					<c:set var="isba_value"><x:out select="$jshtzxqk/isba_value" /></c:set>
					<input id="isba${flag}${index}_value" name="jshtzxqks/jshtzxqk[${flag}${index}]/isba_value" type="hidden" class="required" label="是否已到国税备案" value="<x:out select="$jshtzxqk/isba_value" />" />
					<input id="isba${flag}${index}_name" name="jshtzxqks/jshtzxqk[${flag}${index}]/isba_name" type="hidden" value="<x:out select="$jshtzxqk/isba_name" />" />
					<select id="isba${flag}${index}" onchange="initselectvalue(this.id)">
						<option value="" <c:if test="${empty isba_value}">selected='selected'</c:if> ></option>
						<option value="1" <c:if test="${isba_value == '1'}">selected='selected'</c:if> >是</option>
						<option value="0" <c:if test="${isba_value == '0'}">selected='selected'</c:if>>否</option>
					</select></td>
				<td>
				<input style="width:80%" type="text" value="<x:out select="$jshtzxqk/fpdm"/>" label="发票代码" name="jshtzxqks/jshtzxqk[${flag}${index}]/fpdm" class="input_css required">
				</td>
				<td>
				<input style="width:80%" type="text" value="<x:out select="$jshtzxqk/fphm"/>" label="发票号码" name="jshtzxqks/jshtzxqk[${flag}${index}]/fphm" class="input_css required">
				</td>
				<td>
				<input style="width:80%" type="text" value="<x:out select="$jshtzxqk/fpje"/>" onfocus="InitInput.setNumber(this,7,4,2)" label="发票金额" name="jshtzxqks/jshtzxqk[${flag}${index}]/fpje" class="input_css required">
				</td>
				<td>
				<div>
				<input style="width:80%" type="text" value="<x:out select="$jshtzxqk/baswjg"/>" label="备案税务机关" name="jshtzxqks/jshtzxqk[${flag}${index}]/baswjg" class="input_css">
				</div>
				</td>
				<td>
				<c:set var="dateValue"><x:out select="$jshtzxqk/basj"/></c:set>
				<div>
				<cpt:date name="jshtzxqks/jshtzxqk[${flag}${index}]/basj" label="备案时间" id="basj${flag}${index}"  value="${dateValue }" className="dataSize date"></cpt:date>
				</div>
				</td>
				<td>
				
				<input type="hidden" id="jshtzxqk${flag}${index}_file_code"  name="jshtzxqks/jshtzxqk[${flag}${index}]/file_code" label="上传发票扫描件" class="required" value="<x:out select="$jshtzxqk/file_code" />"   />
				<input type="hidden" id="jshtzxqk${flag}${index}_entity_file_name"  name="jshtzxqks/jshtzxqk[${flag}${index}]/entity_file_name" value="<x:out select="$jshtzxqk/entity_file_name" />"  />
				<span><a id="jshtzxqk${flag}${index}_a" class="color_blue"  href="${ctx}/file/ajax-filedownload?fileCode=<x:out select="$jshtzxqk/file_code" />" ><x:out select="$jshtzxqk/entity_file_name" /></a><br></span>
				<div><input type="file" name="filedata" id="jshtzxqk${flag}${index}" /><button id="button_${flag}${index}" onclick="deleteFile('jshtzxqk${flag}${index}')" class="button_02">删除</button></div>
				
				</td>
				<td>
				<div>
				<input type="hidden" id="jshtzxqkr${flag}${index}_file_code"  name="jshtzxqks/jshtzxqk[${flag}${index}]/file_code2" value="<x:out select="$jshtzxqk/file_code2" />"  label="国税局备案表的扫描件" />
				<input type="hidden" id="jshtzxqkr${flag}${index}_entity_file_name"  name="jshtzxqks/jshtzxqk[${flag}${index}]/entity_file_name2" value="<x:out select="$jshtzxqk/entity_file_name2" />"  />
				<span><a id="jshtzxqkr${flag}${index}_a" class="color_blue"  href="${ctx}/file/ajax-filedownload?fileCode=<x:out select="$jshtzxqk/file_code2" />" ><x:out select="$jshtzxqk/entity_file_name2" /></a><br></span>
				<div><input type="file" name="filedata" id="jshtzxqkr${flag}${index}" /><button id="button2_${flag}${index}" onclick="deleteFile('jshtzxqkr${flag}${index}')" class="button_02">删除</button></div>
				</div>
				<%-- 
				
				<x:out select="$jshtzxqk/target"/>
				<input style="width:80%" type="text" value="" label="国税局备案表的扫描件" name="jshtzxqks/jshtzxqk/gsjbabsmj" class="input_css required"> --%>
				</td>

			</tr>
			<c:set value="${index+1}" var="index" scope="page" />
		</x:forEach>
		<script type="text/javascript">
			showAllDateTag("tblJshtZxqk");
			fileInit_jsht("tblJshtZxqk",
					"JPG,PDF,TIFF,XLS,DOC,WPS", null, "{}");
			$("#tblJshtZxqk").find(".file").css("display","none");
		</script>
	</tbody>
</table>
<div class="clear_h15"></div>

<div align="left">
	<input class="button_02" name="cmdAddbefore" type=button value="添加"
		onclick="if(checkTabLimit('tblJshtZxqk',15,'执行情况最多只能填写15条')){addNewRow('tblJshtZxqk');showDateTag('tblJshtZxqk');fileInit_new_row('tblJshtZxqk','JPG,PDF,TIFF,XLS,DOC,WPS', null, '{}');}try{top.resizeFrame();}catch(e){};">
	<input class="button_02" name="cmdMovePrev" type=button value="上移"
		onclick="movePrev('tblJshtZxqk','selJshtZxqk')"> <input
		class="button_02" name="cmdMoveNext" type=button value="下移"
		onclick="moveNext('tblJshtZxqk','selJshtZxqk')"> <input
		class="button_02" name="cmddel" type=button value="删除"
		onclick="deleteSelectedRow('tblJshtZxqk','执行情况')">
</div>

<script type="text/javascript">
(function(){
	$("#tblJshtZxqk tr:gt(1)").each(function(index,tr){
		var tt = $(tr).children("td").eq(2);
		var inputt = tt.find("input")[0];
		var val = $(inputt).val();
		if(val == '1'){
			//备案税务机关 td
			var td = tt.parent("tr").children("td").eq(6);
			var input = td.find("input")[0];
			$(input).addClass("required");
			//备案时间
			var td2 = tt.parent("tr").children("td").eq(7);
			var input2 = td2.find("input")[0];
			$(input2).addClass("required");
			//国税局备案表的扫描件
			var td3 = tt.parent("tr").children("td").eq(9);
			var input3 = td3.find("input")[0];
			$(input3).addClass("required");
			
			
		}else if(val == '0'){
			//备案税务机关 td
			var td = tt.parent("tr").children("td").eq(6);
			var input = td.find("input")[0];
			var div1 = td.find("div")[0];
			$(input).removeClass("required");
			$(div1).hide();
			//备案时间
			var td2 = tt.parent("tr").children("td").eq(7);
			var input2 = td2.find("input")[0];
			var div2 = td2.find("div")[0];
			$(input2).removeClass("required");
			$(div2).hide();
			//$(img).hide();
			//国税局备案表的扫描件
			var td3 = tt.parent("tr").children("td").eq(9);
			var input3 = td3.find("input")[0];
			var div3 = td3.find("div")[0];
			$(input3).removeClass("required");
			$(div3).hide();
		}
	});
})();


function uploadSuccess_jsht(objId, data, tableId, filetype) {

	var a = $("#"+objId+"_a");
	var hrefValue = a.attr("href");
	var hLength = hrefValue.indexOf("fileCode=");
	var newHref = hrefValue.substring(0, hLength) + "fileCode=" + data[0].fileCode;
	a.attr("href", newHref);
	var t = $("#"+objId+"_file_code");
	$("#"+objId+"_a").text(data[0].fileName);
	$("#"+objId+"_file_code").val(data[0].fileCode);
	$("#"+objId+"_entity_file_name").val(data[0].fileName); 
}


function showFileName_jsht(obj, tableId, type, validateJson) {
	var max='';
	var fileTblId=null;// 文件列表的表格id
	if (tableId == "attachAdd") {
		fileTblId="prp_attachs";
	} else if (tableId == "proattachAdd") {
		fileTblId="product_attachs";
	}
	var filedata = obj.val();
	if (filedata == '')
		return;
	else if(max!=null && $.isNumeric(max) && fileTblId!=null && $("#"+fileTblId+" tr:gt(1)").length>=max){
		var label="";
		if($("#"+fileTblId).attr("label")!=null)
			label=$("#"+fileTblId).attr("label");
		
		scmWarn(label+messageTip.canNotUploadMoreThan+max+messageTip.files1);
		return;
	} else {
		var fileName = filedata.substring(filedata.replace(/\\/g, '/')
				.lastIndexOf('/') + 1);
		var end = fileName.substring(fileName.lastIndexOf(".") + 1,
				fileName.length).toUpperCase();
		if (type.indexOf(end) < 0) {
			scmWarn(messageTip.pleaseUpload + type + messageTip.files2, "100px");
			return;
		}
	}
	$("#" + tableId + " .file").val(fileName);
	ajaxFileUpload_jsht(obj,"prpattach", tableId, type, max, validateJson);
}


/** 上传下载公用接口* */
function ajaxFileUpload_jsht(obj,type, tblId, filetype, max, validateJson) {
	irisajaxFileUpload_jsht(obj,type, tblId, filetype, max, validateJson);
}

function irisajaxFileUpload_jsht(obj,type, tableId, fileType, max, validateJson) {
   var fileObj = obj.attr("id");
  if(obj.parent().parent().attr("id")){
    var index=obj.parent().parent().attr("id").substr("file".length);
    if (type == null || type == '') {
		scmWarn(messageTip.pleaseEnterTypeOfAttachment);
		return;
	}
  }
	$("input[type='file']").not(obj).each(function(){
		$(this).val("");
	});
	prcWin.openWin();// 打开遮罩层
	$.ajaxFileUpload({
		url : ctx + '/file/ajax-fileupload',// 请求地址
		secureuri : false,// 一般设置为false
		fileElementId : 'fileeedata',// 文件的id属性
		limitSize : '10',// 允许上传的文件大小,单位M
		allowType : '',// 允许上传的文件类型.
		data : {
			'type' : type,
			'validateJson':validateJson
		},
		tableId : tableId,// tableID
		dataType : 'json',// 返回值类型
		success : function(data, status) // 服务器成功响应处理函数
		{
			prcWin.closeWin();// 关闭遮罩层
			if (data.result == 'error') {
				scmWarn(data.msg);
			} else {
				uploadSuccess_jsht(fileObj,data, tableId, fileType,index);
				// 回调方法
				// eval(funName+"(data,tableId)");
			}
			$("#" + tableId + " :file").each(function(i) {
				$(this).change(function() {
					showFileName_jsht($(this), tableId, fileType, validateJson);
				});
			});
		},
		error : function(data, status, e)// 服务器响应失败处理函数
		{
			$('.file').each(function(j) {
				$(this).attr('value', '');
			});
			$("#" + tableId + " :file").each(function(i) {
				$(this).change(function() {
					showFileName_jsht($(this), tableId, fileType, validateJson);
				});
			});
			prcWin.closeWin();// 关闭遮罩层
			if (data && data.responseText && data.responseText.indexOf('413') > -1) {
				scmError("上传的文件超过限制大小！");
			} else {
				scmError(status);
			}
		}/*,
		complete:function()
		{
			prcWin.closeWin();// 关闭遮罩层
		}*/
	});
	
}

function deleteFile(objId){
	$("#"+objId+"_file_code").val("");
	$("#"+objId+"_entity_file_name").val(""); 
	$("#"+objId+"_a").text("");
	return;
}


function fileInit_new_row(tableId, type, width, validateJson) {

	var newtr = $('#'+tableId+ ' tr:last');
	var imgres="";
	
	if(locale=="en_US"){
	    imgres="Upload_EN.gif";
	    
	}else{
		imgres="Upload_2.gif";
		
	}
	$(newtr).find(".file").css("display","none");
	$(newtr).find(":file").css("margin-left",'0px');
	$(newtr).find(":file").unbind();
	/* $(newtr).find(":file").live("change",function() {
		if(type==null){
			showFileName_jsht($(this), tableId, type,null, validateJson);
		}else{
			showFileName_jsht($(this), tableId, type, validateJson);	
		}
	});  */
	 $(newtr).find(":file").each(function(i) {
		$(this).change(function() {
			if(type==null){
				showFileName_jsht($(this), tableId, type,null, validateJson);
			}else{
				showFileName_jsht($(this), tableId, type, validateJson);	
			}
			
		});
	});
}
function initselectvalue(objId){
	var val = $("#"+objId).val();
	if(val == '1'){
		$("#"+objId+"_value").val("1");
		$("#"+objId+"_name").val("是");
		//备案税务机关 td
		var td = $("#"+objId).parent("td").parent("tr").children("td").eq(6);
		var input = td.find("input")[0];
		var div1 = td.find("div")[0];
		$(input).addClass("required");
		$(div1).show();
		//备案时间
		var td2 = $("#"+objId).parent("td").parent("tr").children("td").eq(7);
		var input2 = td2.find("input")[0];
		var div2 = td2.find("div")[0];
		$(input2).addClass("required");
		$(div2).show();
		
		//国税局备案表的扫描件
		var td3 = $("#"+objId).parent("td").parent("tr").children("td").eq(9);
		var input3 = td3.find("input")[0];
		var div3 = td3.find("div")[0];
		$(input3).addClass("required");
		$(div3).show();
	}else if(val == '0'){
		$("#"+objId+"_value").val("0");
		$("#"+objId+"_name").val("否");
		//备案税务机关 td
		var td = $("#"+objId).parent("td").parent("tr").children("td").eq(6);
		var input = td.find("input")[0];
		var div1 = td.find("div")[0];
		$(input).removeClass("required");
		$(input).val("");
		$(div1).hide();
		//备案时间
		var td2 = $("#"+objId).parent("td").parent("tr").children("td").eq(7);
		var input2 = td2.find("input")[0];
		var div2 = td2.find("div")[0];
		$(input2).removeClass("required");
		$(input2).val("");
		$(div2).hide();
		//国税局备案表的扫描件
		var td3 = $("#"+objId).parent("td").parent("tr").children("td").eq(9);
		var input3 = td3.find("input")[0];
		var input3_1 = td3.find("input")[1];
		var div3 = td3.find("div")[0];
		var a = td3.find("a")[0];
		$(input3).removeClass("required");
		$(input3).val("");
		$(input3_1).val("");
		$(a).text("");
		$(div3).hide();
	}else{
		$("#"+objId+"_value").val("");
		$("#"+objId+"_name").val("");
	}
}
</script>